package main

import (
	"fmt"
	"gitee.com/lywtimer/practice-go/utils"
	"gitee.com/lywtimer/practice-go/utils/retriever/mock"
	"gitee.com/lywtimer/practice-go/utils/retriever/real"
	"time"
)

const url = "https://www.imooc.com"

func main() {

	var r utils.Retriever

	r = &real.Retriever{
		UserAgent: "Mozilla/5.0",
		TimeOut:   time.Minute,
	}
	utils.Inspect(r)
	retriever := &mock.Retriever{Contents: "this is a fake imooc.com"}
	r = retriever
	utils.Inspect(r)
	//Type assertion
	if realRetriever, ok := r.(*real.Retriever); ok {
		fmt.Println(realRetriever.TimeOut)
	} else {
		fmt.Println("not a real retriever")
	}
	//fmt.Println(download(r))
	fmt.Println("try a session")
	fmt.Println(session(retriever))
}

func download(r utils.Retriever) string {
	return r.Get(url)
}

func post(poster utils.Poster) string {
	return poster.Post(url, map[string]string{
		"name":   "ccmouse",
		"course": "golang",
	})
}

func session(s utils.Session) string {
	s.Post(url, map[string]string{
		"contents": "another faked imooc.com",
	})
	return s.Get(url)
}
